package com.scu.bank.util;

import org.apache.commons.lang3.Validate;

import java.util.*;

public final class ListUtils {
    public static List<?> toList(Object target) {
        Validate.notNull(target, "Cannot convert null to list");
        if (target instanceof List) {
            return (List)target;
        } else if (target.getClass().isArray()) {
            return new ArrayList(Arrays.asList((Object[])target));
        } else if (!(target instanceof Iterable)) {
            throw new IllegalArgumentException("Cannot convert object of class \"" + target.getClass().getName() + "\" to a list");
        } else {
            List<Object> elements = new ArrayList(10);
            Iterator var2 = ((Iterable)target).iterator();

            while(var2.hasNext()) {
                Object element = var2.next();
                elements.add(element);
            }

            return elements;
        }
    }

    public static int size(List<?> target) {
        Validate.notNull(target, "Cannot get list size of null");
        return target.size();
    }

    public static boolean isEmpty(List<?> target) {
        return target == null || target.isEmpty();
    }

    public static boolean contains(List<?> target, Object element) {
        Validate.notNull(target, "Cannot execute list contains: target is null");
        return target.contains(element);
    }

    public static boolean containsAll(List<?> target, Object[] elements) {
        Validate.notNull(target, "Cannot execute list containsAll: target is null");
        Validate.notNull(elements, "Cannot execute list containsAll: elements is null");
        return containsAll(target, (Collection) Arrays.asList(elements));
    }

    public static boolean containsAll(List<?> target, Collection<?> elements) {
        Validate.notNull(target, "Cannot execute list contains: target is null");
        Validate.notNull(elements, "Cannot execute list containsAll: elements is null");
        return target.containsAll(elements);
    }

    public static <T extends Comparable<? super T>> List<T> sort(List<T> list) {
        Validate.notNull(list, "Cannot execute list sort: list is null");
        Object[] a = list.toArray();
        Arrays.sort(a);
        return fillNewList(a, list.getClass());
    }

    private static <T> List<T> fillNewList(Object[] a, Class<? extends List> listType) {
        Object newList;
        try {
            newList = (List)listType.getConstructor().newInstance();
        } catch (Exception var7) {
            newList = new ArrayList(a.length + 2);
        }

        Object[] var3 = a;
        int var4 = a.length;

        for(int var5 = 0; var5 < var4; ++var5) {
            Object object = var3[var5];
            ((List)newList).add(object);
        }

        return (List)newList;
    }

    private ListUtils() {
    }
}
